package com.javaspeak.algorithm.fibonacci.conciserecursive;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

/**
 * Class used to answer question:
 * <p>
 * Write a program that generates the Fibonacci sequence. The fibonacci
 * sequence is 1,1,2,3,5,8,13,21
 * </p>
 * @author John Dickerson
 */
public class FibonacciGenerator {

    private static List<BigInteger> cache = new ArrayList<BigInteger>();

    static {
        cache.add( BigInteger.ZERO );
        cache.add( BigInteger.ONE );
    }

    public static BigInteger getNumber( int number ) {

        if ( number >= cache.size() ) {

            cache.add( number,
                    getNumber( number - 1 ).add( getNumber( number -2 ) ) );
        }

        return cache.get( number );
    }


    public static  List<BigInteger> getCache(){

        return cache;
    }


    public static void main( String[] args ) {

        for ( int i=0; i<=100; i++ ) {

            System.out.print( getNumber( i ) + ", " );
        }
    }
}
